#include <iostream>
#include <unistd.h>
#include <sys/fcntl.h>
#include <string.h>

using std::cout;
using std::endl;

void test()
{
    int fd = open("../data/hello.txt", O_CREAT | O_RDWR, 0666);
    char buf[1024]{0};
    int ret = read(fd, buf, 10);
    if(ret < 0) {
        perror("read");
        exit(-1);
    }
    cout << buf << endl;

    bzero(buf, 10);
    dup2(fd, STDOUT_FILENO);
    cout << "hello\nworld\n";

    close(fd);
}

int main(int args, char *argv[])
{
    test();
    return 0;
}